package com.yingside.clazz.date;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Test2 {
    public static void main(String[] args) {
        Calendar calendar = Calendar.getInstance();
        // 获取时间
        //统一会用到一个方法 get(int)

        //通过get方法，里面放入相应的你要获取的值，这些值都是静态变量
        int year = calendar.get(Calendar.YEAR);
        System.out.println(year);
        int month = calendar.get(Calendar.MONTH);
        //注意月份从0开始
        System.out.println("month = " + month);

        //这个get方法，可以直接获取到一些比较特殊的时间
        //一年中的第几周
        int WEEK_OF_YEAR = calendar.get(Calendar.WEEK_OF_YEAR);
        System.out.println("WEEK_OF_YEAR = " + WEEK_OF_YEAR);
        //一年的第几天
        int DAY_OF_YEAR = calendar.get(Calendar.DAY_OF_YEAR);
        System.out.println("DAY_OF_YEAR = " + DAY_OF_YEAR);

        //如果要设置时间使用set方法
        calendar.set(2010,2,11);

        month = calendar.get(Calendar.MONTH);
        System.out.println(" 日期修改之后 month = " + month);

        //把Calendar转换为Date
        Date date = calendar.getTime();
        System.out.println("date = " + date);

        System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date));


        //把Date转换为Calendar
        Calendar c2 = Calendar.getInstance();
        c2.setTime(date);
    }
}
